/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package c0907m.group2.aitsm.gui.component;

import javax.swing.*;
import java.awt.*;

/**
 * @author ISTC
 */
public class StatusBar extends javax.swing.JLabel {
    public static final int MESSAGE_TYPE = 1;
    public static final int ERROR_TYPE = 2;
    public static final int WARNING_TYPE = 3;

    public StatusBar() {
        super();
        doStyle();
    }

    /**
     * Styling
     */
    private void doStyle() {
        setVerticalAlignment(javax.swing.SwingConstants.CENTER);
        setVerticalTextPosition(javax.swing.SwingConstants.CENTER);
        setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        setFont(new Font("Tahoma", Font.BOLD, 12));
    }

    /**
     * Display message on status bar.
     *
     * @param message     message to display.
     * @param messageType type of message.
     */
    public void setMessage(String message, int messageType) {
        if (messageType == MESSAGE_TYPE) {
            setForeground(Color.gray);
            setText(message);
        }

        if (messageType == WARNING_TYPE) {
            setForeground(Color.blue);
            setText("WARNING: " + message);
        }

        if (messageType == ERROR_TYPE) {
            setForeground(Color.red);
            setText("ERROR: " + message);
        }

    }

    /**
     * Display message with icon.
     *
     * @param message     message to display.
     * @param messageType type of message.
     * @param icon        icon to display.
	 * @throws Exception error.
     */
    public void setMessage(String message, int messageType, Icon icon) throws Exception {
        setMessage(message, messageType);
        setIcon(icon);
    }
}
